home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / findutil.1 / findutil / findutils-4.1 / find / defs.h next >
Encoding:
C/C++ Source or Header  |  1994-11-02  |  11.4 KB  |  333 lines

  1. /* defs.h -- data types and declarations.
  2.    Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
  19. #include <string.h>
  20. #else
  21. #include <strings.h>
  22. #ifndef strchr
  23. #define strchr index
  24. #endif
  25. #ifndef strrchr
  26. #define strrchr rindex
  27. #endif
  28. #endif
  29.  
  30. #include <errno.h>
  31. #ifndef errno
  32. extern int errno;
  33. #endif
  34.  
  35. #ifdef STDC_HEADERS
  36. #include <stdlib.h>
  37. #endif
  38.  
  39. #ifdef HAVE_UNISTD_H
  40. #include <unistd.h>
  41. #endif
  42.  
  43. #include <time.h>
  44.  
  45. #include "regex.h"
  46.  
  47. #if __STDC__
  48. # define P_(s) s
  49. #else
  50. # define P_(s) ()
  51. #endif
  52.  
  53. /* Not char because of type promotion; NeXT gcc can't handle it.  */
  54. typedef int boolean;
  55. #define        true    1
  56. #define        false    0
  57.  
  58. /* Pointer to function returning boolean. */
  59. typedef boolean (*PFB)();
  60.  
  61. /* The number of seconds in a day. */
  62. #define        DAYSECS        86400
  63.  
  64. /* Argument structures for predicates. */
  65.  
  66. enum comparison_type
  67. {
  68.   COMP_GT,
  69.   COMP_LT,
  70.   COMP_EQ
  71. };
  72.  
  73. enum predicate_type
  74. {
  75.   NO_TYPE,
  76.   PRIMARY_TYPE,
  77.   UNI_OP,
  78.   BI_OP,
  79.   OPEN_PAREN,
  80.   CLOSE_PAREN
  81. };
  82.  
  83. enum predicate_precedence
  84. {
  85.   NO_PREC,
  86.   COMMA_PREC,
  87.   OR_PREC,
  88.   AND_PREC,
  89.   NEGATE_PREC,
  90.   MAX_PREC
  91. };
  92.  
  93. struct long_val
  94. {
  95.   enum comparison_type kind;
  96.   unsigned long l_val;
  97. };
  98.  
  99. struct size_val
  100. {
  101.   enum comparison_type kind;
  102.   int blocksize;
  103.   unsigned long size;
  104. };
  105.  
  106. struct path_arg
  107. {
  108.   short offset;            /* Offset in `vec' of this arg. */
  109.   short count;            /* Number of path replacements in this arg. */
  110.   char *origarg;        /* Arg with "{}" intact. */
  111. };
  112.  
  113. struct exec_val
  114. {
  115.   struct path_arg *paths;    /* Array of args with path replacements. */
  116.   char **vec;            /* Array of args to pass to program. */
  117. };
  118.  
  119. /* The format string for a -printf or -fprintf is chopped into one or
  120.    more `struct segment', linked together into a list.
  121.    Each stretch of plain text is a segment, and
  122.    each \c and `%' conversion is a segment. */
  123.  
  124. /* Special values for the `kind' field of `struct segment'. */
  125. #define KIND_PLAIN 0        /* Segment containing just plain text. */
  126. #define KIND_STOP 1        /* \c -- stop printing and flush output. */
  127.  
  128. struct segment
  129. {
  130.   int kind;            /* Format chars or KIND_{PLAIN,STOP}. */
  131.   char *text;            /* Plain text or `%' format string. */
  132.   int text_len;            /* Length of `text'. */
  133.   struct segment *next;        /* Next segment for this predicate. */
  134. };
  135.  
  136. struct format_val
  137. {
  138.   struct segment *segment;    /* Linked list of segments. */
  139.   FILE *stream;            /* Output stream to print on. */
  140. };
  141.  
  142. struct predicate
  143. {
  144.   /* Pointer to the function that implements this predicate.  */
  145.   PFB pred_func;
  146.  
  147.   /* Only used for debugging, but defined unconditionally so individual
  148.      modules can be compiled with -DDEBUG.  */
  149.   char *p_name;
  150.  
  151.   /* The type of this node.  There are two kinds.  The first is real
  152.      predicates ("primaries") such as -perm, -print, or -exec.  The
  153.      other kind is operators for combining predicates. */
  154.   enum predicate_type p_type;
  155.  
  156.   /* The precedence of this node.  Only has meaning for operators. */
  157.   enum predicate_precedence p_prec;
  158.  
  159.   /* True if this predicate node produces side effects. */
  160.   boolean side_effects;
  161.  
  162.   /* True if this predicate node requires a stat system call to execute. */
  163.   boolean need_stat;
  164.  
  165.   /* Information needed by the predicate processor.
  166.      Next to each member are listed the predicates that use it. */
  167.   union
  168.   {
  169.     char *str;            /* fstype [i]lname [i]name [i]path */
  170.     struct re_pattern_buffer *regex; /* regex */
  171.     struct exec_val exec_vec;    /* exec ok */
  172.     struct long_val info;    /* atime ctime mtime inum links */
  173.     struct size_val size;    /* size */
  174.     uid_t uid;            /* user */
  175.     gid_t gid;            /* group */
  176.     time_t time;        /* newer */
  177.     unsigned long perm;        /* perm */
  178.     unsigned long type;        /* type */
  179.     FILE *stream;        /* fprint fprint0 */
  180.     struct format_val printf_vec; /* printf fprintf */
  181.   } args;
  182.  
  183.   /* The next predicate in the user input sequence,
  184.      which repesents the order in which the user supplied the
  185.      predicates on the command line. */
  186.   struct predicate *pred_next;
  187.  
  188.   /* The right and left branches from this node in the expression
  189.      tree, which represents the order in which the nodes should be
  190.      processed. */
  191.   struct predicate *pred_left;
  192.   struct predicate *pred_right;
  193. };
  194.  
  195. /* find library function declarations.  */
  196.  
  197. /* dirname.c */
  198. char *dirname P_((char *path));
  199.  
  200. /* error.c */
  201. void error P_((int status, int errnum, char *message, ...));
  202.  
  203. /* listfile.c */
  204. void list_file P_((char *name, char *relname, struct stat *statp, FILE *stream));
  205. char *get_link_name P_((char *name, char *relname));
  206.  
  207. /* savedir.c */
  208. char *savedir P_((char *dir, unsigned name_size));
  209.  
  210. /* stpcpy.c */
  211. #if !HAVE_STPCPY
  212. char *stpcpy P_((char *dest, const char *src));
  213. #endif
  214.  
  215. /* xgetcwd.c */
  216. char *xgetcwd P_((void));
  217.  
  218. /* xmalloc.c */
  219. #if __STDC__
  220. #define VOID void
  221. #else
  222. #define VOID char
  223. #endif
  224.  
  225. VOID *xmalloc P_((size_t n));
  226. VOID *xrealloc P_((VOID *p, size_t n));
  227.  
  228. /* xstrdup.c */
  229. char *xstrdup P_((char *string));
  230.  
  231. /* find global function declarations.  */
  232.  
  233. /* fstype.c */
  234. char *filesystem_type P_((char *path, char *relpath, struct stat *statp));
  235.  
  236. /* parser.c */
  237. PFB find_parser P_((char *search_name));
  238. boolean parse_close P_((char *argv[], int *arg_ptr));
  239. boolean parse_open P_((char *argv[], int *arg_ptr));
  240. boolean parse_print P_((char *argv[], int *arg_ptr));
  241.  
  242. /* pred.c */
  243. boolean pred_amin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  244. boolean pred_and P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  245. boolean pred_anewer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  246. boolean pred_atime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  247. boolean pred_close P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  248. boolean pred_cmin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  249. boolean pred_cnewer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  250. boolean pred_comma P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  251. boolean pred_ctime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  252. boolean pred_empty P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  253. boolean pred_exec P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  254. boolean pred_false P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  255. boolean pred_fls P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  256. boolean pred_fprint P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  257. boolean pred_fprint0 P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  258. boolean pred_fprintf P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  259. boolean pred_fstype P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  260. boolean pred_gid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  261. boolean pred_group P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  262. boolean pred_ilname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  263. boolean pred_iname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  264. boolean pred_inum P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  265. boolean pred_ipath P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  266. boolean pred_links P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  267. boolean pred_lname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  268. boolean pred_ls P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  269. boolean pred_mmin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  270. boolean pred_mtime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  271. boolean pred_name P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  272. boolean pred_negate P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  273. boolean pred_newer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  274. boolean pred_nogroup P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  275. boolean pred_nouser P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  276. boolean pred_ok P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  277. boolean pred_open P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  278. boolean pred_or P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  279. boolean pred_path P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  280. boolean pred_perm P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  281. boolean pred_print P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  282. boolean pred_print0 P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  283. boolean pred_prune P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  284. boolean pred_regex P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  285. boolean pred_size P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  286. boolean pred_true P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  287. boolean pred_type P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  288. boolean pred_uid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  289. boolean pred_used P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  290. boolean pred_user P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  291. boolean pred_xtype P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
  292. char *find_pred_name P_((PFB pred_func));
  293. #ifdef DEBUG
  294. void print_tree P_((struct predicate *node, int indent));
  295. void print_list P_((struct predicate *node));
  296. #endif /* DEBUG */
  297.  
  298. /* tree.c */
  299. struct predicate *get_expr P_((struct predicate **input, int prev_prec));
  300. boolean opt_expr P_((struct predicate **eval_treep));
  301. boolean mark_stat P_((struct predicate *tree));
  302.  
  303. /* util.c */
  304. char *basename P_((char *fname));
  305. struct predicate *get_new_pred P_((void));
  306. struct predicate *get_new_pred_chk_op P_((void));
  307. struct predicate *insert_primary P_((boolean (*pred_func )()));
  308. void usage P_((char *msg));
  309.  
  310. extern char *program_name;
  311. extern struct predicate *predicates;
  312. extern struct predicate *last_pred;
  313. extern boolean do_dir_first;
  314. extern int maxdepth;
  315. extern int mindepth;
  316. extern int curdepth;
  317. extern time_t cur_day_start;
  318. extern boolean full_days;
  319. extern boolean no_leaf_check;
  320. extern boolean stay_on_filesystem;
  321. extern boolean stop_at_current_level;
  322. extern boolean have_stat;
  323. extern char *rel_pathname;
  324. #ifndef HAVE_FCHDIR
  325. extern char *starting_dir;
  326. #else
  327. extern int starting_desc;
  328. #endif
  329. extern int exit_status;
  330. extern int path_length;
  331. extern int (*xstat) ();
  332. extern boolean dereference;
  333.